 package net.go176.backpack.command;
 
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 import net.go176.backpack.Backpack;
 import org.bukkit.ChatColor;
 import org.bukkit.command.Command;
 import org.bukkit.command.CommandExecutor;
 import org.bukkit.command.CommandSender;
 import org.bukkit.command.TabCompleter;
 import org.bukkit.command.TabExecutor;
 
 
 public class CommandManager
   implements CommandExecutor, TabExecutor
 {
   final Backpack p;
   CommandBase cmdMain;
   List<CommandBase> cmds;
   static final String TITLE = "&7&l====[My Backpack]====";
   
   public CommandManager(Backpack plugin) {
     this.p = plugin;
     this.cmdMain = new CmdMain(this);
     this.cmds = Arrays.asList(new CommandBase[] {
           new CmdHelp(this), 
           new CmdLinks(this), 
           new CmdOpen(this), 
           new CmdReload(this), 
           new CmdInfo(this)
         });
     this.p.getCommand("mybackpack").setExecutor(this);
     this.p.getCommand("mybackpack").setTabCompleter((TabCompleter)this);
   }
 
   
   public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) {
     this.cmdMain.preExecute(cs, cmd, label, args);
     return true;
   }
 
   
   public List<String> onTabComplete(CommandSender cs, Command cmd, String label, String[] args) {
     if (this.cmdMain.canTabComplete(cs, cmd, label, args))
       return this.cmdMain.tabComplete(cs, cmd, label, args); 
     return null;
   }
   
   class CmdMain
     extends CommandBase {
     public CmdMain(CommandManager cmdMan) {
       super(cmdMan);
       this.permission = "mybackpack.command";
     }
 
     
     protected void execute(CommandSender cs, Command cmd, String label, String[] args) {
       if (args.length == 0) {
         CommandManager.sendMsg(cs, CommandManager.getUsage(label));
         return;
       } 
       CommandBase mycmd = null;
       for (CommandBase c : CommandManager.this.cmds) {
         if (c.labels.contains(args[0].toLowerCase())) {
           mycmd = c;
           break;
         } 
       } 
       if (mycmd != null) {
         mycmd.preExecute(cs, cmd, label, args);
       } else {
         CommandManager.sendMsg(cs, CommandManager.getUsage(label));
       } 
     }
     
     protected List<String> tabComplete(CommandSender cs, Command cmd, String label, String[] args) {
       if (args.length == 1) {
         List<String> cmdLabels = new ArrayList<>();
         for (CommandBase c : CommandManager.this.cmds)
           cmdLabels.addAll(c.labels); 
         List<String> cmdNames = CommandManager.getCompletions(args[0], cmdLabels);
         if (!cmdNames.isEmpty())
           return cmdNames; 
       } else {
         for (CommandBase c : CommandManager.this.cmds) {
           if (c.canTabComplete(cs, cmd, label, args) && c.labels.contains(args[0].toLowerCase()))
             return c.tabComplete(cs, cmd, label, args); 
         } 
       } 
       return null;
     }
   }
 
   
   static String getUsage(String label) {
     return "&c/" + label + " help or /" + label + " ? for more infomation";
   }
   
   public static void sendMsg(CommandSender cs, String msg) {
     cs.sendMessage(ChatColor.translateAlternateColorCodes('&', msg));
   }
   
   public static void sendMsg(CommandSender cs, String[] msgs) {
     String[] clone = (String[])msgs.clone();
     for (int i = 0; i < clone.length; i++)
       clone[i] = ChatColor.translateAlternateColorCodes('&', clone[i]); 
     cs.sendMessage(clone);
   }
   
   public static String lister(Collection<String> list, String sep, String sur) {
     StringBuilder result = new StringBuilder();
     Iterator<String> it = list.iterator();
     while (it.hasNext()) {
       result.append(String.valueOf(sur) + (String)it.next() + sur);
       if (it.hasNext())
         result.append(sep); 
     } 
     return result.toString();
   }
   
   public static List<String> getCompletions(String cmdArg, Collection<String> c) {
     List<String> cmdNames = new ArrayList<>();
     for (String str : c) {
       if (str.toLowerCase().startsWith(cmdArg.toLowerCase()))
         cmdNames.add(str); 
     } 
     return cmdNames;
   }
 }


/* Location:              D:\User\Xuan\Downloads\MyBackpack1.2.5.jar!\net\saralab\mybackpack\command\CommandManager.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.1.3
 */